package xin.yangshuai.mybatisgeneratorweb.vo;

/**
 * BaseResponse
 *
 * @author shuai
 * @date 2020/11/25
 */
public class BaseResponse<T> {

    interface Constant {
        int SUCCESS_CODE = 0;
        int ERROR_CODE = -1;
        String SUCCESS_MESSAGE = "请求成功";
        String ERROR_MESSAGE = "请求失败";
    }

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回提示信息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    public BaseResponse() {
    }

    public BaseResponse(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> BaseResponse success(T data) {
        return new BaseResponse(Constant.SUCCESS_CODE, Constant.SUCCESS_MESSAGE, data);
    }

    public static <T> BaseResponse success(T data, String message) {
        return new BaseResponse(Constant.SUCCESS_CODE, message, data);
    }

    public static BaseResponse error() {
        return new BaseResponse(Constant.ERROR_CODE, Constant.ERROR_MESSAGE, null);
    }

    public static BaseResponse error(String message) {
        return new BaseResponse(Constant.ERROR_CODE, message, null);
    }
}
